#!/usr/bin/env python

import os
import sys
import re


f = open(sys.argv[1], "r")
lines = f.readlines()
entry = {}
count = 1
for line in lines:
    if "RCU KFREE" in line:
        addr = line.split("=")[1].strip()
        entry[addr] = "free:%d" % count
        #print "free: addr = %s" % addr
    elif "STRCPY event name" in line:
        addr = line.split("=")[1].strip()
        if "free" in entry[addr]:
            num = entry[addr].split(':')[1]
            print "UAF happened in line %d, memory addr = %s, freed in line %s" % (count, addr, num)
    elif "KMALLOC name" in line:
        addr = line.split("=")[1].strip()
        entry[addr] = "use"

    count += 1

f.close()
sys.exit(0)
    
